package start.spring.basic.page;

import java.util.List;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 
 * ****************************************************************************
 *
 * @author(作者)：xuyongyun	
 * @date(创建日期)：2020年5月13日
 ******************************************************************************
 */
@Data
@ApiModel("分页结果对象")
public class PageResult<T> {
	
	@ApiModelProperty(value = "当前页",example = "1")
	private long current = 1;
	
	@ApiModelProperty(value = "每页数据量",example = "20")
	private long size = 20;
	
	@ApiModelProperty(value = "总记录数",example = "0")
	private long total = 0;
	
	@ApiModelProperty(value = "总页数",example = "0")
	private long pages = 0;
	
	@ApiModelProperty("结果列表")
	private List<T> records;
	
	public void setCalPages() {
		if (total % size == 0){
	    	this.pages = total/size;
	    }else{
	    	this.pages = total/size + 1;
	    }
	}
	
	/**
	 * 根据参数计算总页数，兼容多个工具中long及int类型变量不兼容文件
	 *	
	 * @return
	 * @since           1.0
	 */
	public int getStartIndex(int current,int size) {
		int startIndex = (current - 1) * size;
    	return startIndex;
	}
	
}
